package com.journaldev.spring.model;

import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Table(name="toathuoc")
public class Prescription {
	public Prescription(){
		
	}

	public Prescription(int id, Patient belongToPatient,
			String diagnostic, String note, Long cost, Date createDate,
			Set<PrescriptionMedicine> prescMedicine) {
		super();
		this.id = id;
		this.belongToPatient = belongToPatient;
		this.diagnostic = diagnostic;
		this.note = note;
		this.cost = cost;
		this.createDate = createDate;
		this.prescriptionMedicine = prescMedicine;
	}

	@Id
	@Column(name="id_toathuoc")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Patient getBelongToPatient() {
		return belongToPatient;
	}

	public void setBelongToPatient(Patient belongToPatient) {
		this.belongToPatient = belongToPatient;
	}

	public String getDiagnostic() {
		return diagnostic;
	}

	public void setDiagnostic(String diagnostic) {
		this.diagnostic = diagnostic;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public Long getCost() {
		return cost;
	}

	public void setCost(Long cost) {
		this.cost = cost;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "id_benhnhan")
	private Patient belongToPatient;
	
	@Column(name="chuandoan")
	private String diagnostic;
	
	@Column(name="ghichu")
	private String note;
	
	@Column(name="dongia")
	private Long cost;
	
	@Column(name="ngay_xuat_toa")
	@DateTimeFormat(pattern = "dd/MM/yyyy")
	private Date createDate;

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	@OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.prescription", cascade=CascadeType.ALL, orphanRemoval = true)
	private Set<PrescriptionMedicine> prescriptionMedicine = new HashSet<PrescriptionMedicine>();
	
	
	public Set<PrescriptionMedicine> getPrescriptionMedicine() {
		return this.prescriptionMedicine;
	}
 
	public void setPrescriptionMedicine(Set<PrescriptionMedicine> presMedicine) {
		this.prescriptionMedicine = presMedicine;
	}
}
